<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

    <%@include file="../common/include.jsp" %>

        <!DOCTYPE html>
        <html>

        <head>

            <meta charset="UTF-8">
            <base href="<%=basePath%>">





        </head>

        <body>





            <!--  新增数据 -->
            <div class="form-group form-inline" style="margin:20px">
                <strong style="font-size:1.2em"> 一级菜单:</strong>
                <select id="addFirstMenu" onchange="FirstMenuChange( )" name="addFirstMenu" class="  form-control" style="margin-left:10px">


			 <c:forEach var="item" items="${typeList}">

				 <option value="${item.id}">${item.name}</option>

			 </c:forEach>
		 </select>

                <strong style="font-size:1.2em;margin-left:10px"> 二级菜单:</strong>
                <select id="addSecMenu" name="addSecMenu" class=" form-control">
			 <option value=0>-全 部-</option>
			 <%-- <c:forEach var="childItem" items="${childList}">
                 <option value="${childItem.id}">${childItem.name}</option>
             </c:forEach> --%>

		 </select>

                <label for="action" style="margin-left:10px">
			 <strong style="font-size:1.2em"> 路径 ：</strong>
		 </label>
                <input type="text" class="form-control" id="action" name="action" style="    width: 280px;" />

                <label for="description" style="margin-left:10px">
			 <strong style="font-size:1.2em">  说明： </strong>
		 </label>
                <input type="text" class="form-control" id="description" name="description" style="    width: 140px;" />


                <input type="button" name="button" value="增加" class="btn btn-primary " style="margin-left:20px" onclick="addRightAction()" />
            </div>


            <div style="    border: 1px solid #dfdfdf;    margin: 10px;">



                <div class="row" style="margin-top:20px;margin-left:15px;margin-right: 20px">
                    <form method="post" action="getRightActionList.html" style="    background-color: #EAEAEA;    margin: 0; padding: 0;  overflow: hidden;  color: #4C4C4C;">

                        <div class="form-group form-inline" style="margin:20px">
                            <strong style="font-size:1.2em"> 一级菜单:</strong>
                            <select id="superMenuId" onchange="superMenuIdchanged() " name="conditions['superMenuId']" class="  form-control" style="margin-left:10px">
						  <option value="0">-全 部-</option>

						  <c:forEach var="item" items="${typeList}">

							  <option value="${item.id}">${item.name}</option>

						  </c:forEach>
					  </select>

                            <strong style="font-size:1.2em;margin-left:10px"> 二级菜单:</strong>
                            <select id="secMenuId" name="conditions['secMenuId']" class=" form-control">
						  <option value=0>-全 部-</option>
						  <c:forEach var="childItem" items="${childList}">
							  <option value="${childItem.id}">${childItem.name}</option>
						  </c:forEach>

					  </select>

                            <label for="actionPath" style="margin-left:10px">
						  <strong style="font-size:1.2em"> 路径字符串模糊查询： </strong>
					  </label>
                            <input type="text" class="form-control" id="actionPath" name="conditions['actionPath']" style="width:300px" value="${pages.conditions.actionPath}">
                            <input type="submit" name="button" value="查 询" class="btn btn-primary" />
                        </div>


                    </form>



                </div>

                <div style="margin-left:16px; margin-top:10px;margin-bottom:2px;margin-right:20px">
                    <table class="table table-striped  table-bordered table-hover">
                        <thead>
                            <tr style="background-color:#efefef; ">

                                <th>一级模块</th>
                                <th>二级模块</th>
                                <th>路径url</th>
                                <th>路径说明</th>




                                <th>操作</th>
                            </tr>
                        </thead>



                        <tbody id="tbody">
                            <c:forEach var="item" items="${pages.pageDatas}">
                                <tr id="tr_${item.id }">

                                    <td> ${item.name }</td>
                                    <td> ${item.fatherMenu }</td>
                                    <td>
                                        <c:out value="${item.action}" />
                                    </td>
                                    <td>
                                        <c:out value="${item.description}" />
                                    </td>


                                    <td>

                                        <a href="javascript:void(0)" onclick="deleteById(${item.id})" class="handleicon" title="删除"> <i class="fa fa-times"></i></a>
                                    </td>

                                </tr>
                            </c:forEach>


                        </tbody>

                    </table>


                    <!--  使用自己的 分页标签  前面三个是固定的必须参数 后面的url  是请求路径，可以根据情况  加或者不加参数-->

                    <c:if test="${pages.totalPages>1 }">
                        <page:pager pageSize="${pages.pageSize}" currPage="${pages.currPage}" totalRecords="${pages.totalRecords}" url="${pageContext.request.contextPath}/getRightActionList.html?conditions['superMenuId']=${pages.conditions.superMenuId}&conditions['secMenuId']=${pages.conditions.secMenuId}&conditions['actionPath']=${pages.conditions.actionPath}"
                        />

                    </c:if>




                </div>




            </div>







        </body>


        <script>
            //定义全局变量
            var rightActionId = 0;
        </script>

        <!-- 本段 javaacript用来处理 编辑 路径 -->
        <script>
        </script>



        <script type="text/javascript">
            //初始化  下拉列表的 选中项

            function initSelect() {
                // 根据 父id 设置 select的选中值  value里的！
                $("#superMenuId").val(${
                    pages.conditions.superMenuId
                });

                $("#secMenuId").val(${
                    pages.conditions.secMenuId
                });

                FirstMenuChange();

            }

            initSelect();



            /* 删除     */
            function deleteById(id) {

                if (confirm("真的需要删除该ACTION吗？")) {

                    $.ajax({
                        type: 'POST',
                        url: '${pageContext.request.contextPath}/deleteById.html',
                        data: {
                            "id": id
                        },
                        dataType: 'json', //要求服务器返回 json对象 而不是字符串
                        success: function(data) {

                            if (data.code == 1) {
                                //$("#tr_" + id).remove();
                                layer.msg('删除成功');

                                window.location.href = "${pageContext.request.contextPath}/getRightActionList.html"

                            } else {
                                layer.msg(data.msg);
                            }
                        },
                        error: function() {
                            alert("请求出错，可能连接不上服务器");
                        }

                    })




                }


            }

            /* 响应菜单联动 */
            function superMenuIdchanged() {
                var op = $("#superMenuId option:selected");
                var parentId = op.val();

                if (parentId == 0) {
                    $("#secMenuId").html("<option value=0>全 部</option>");

                } else {
                    $.ajax({
                        type: 'POST',
                        url: '${pageContext.request.contextPath}/getSecMenuByFartherId.html',
                        data: {
                            "parentId": parentId
                        },
                        dataType: 'json', //要求服务器返回 json对象 而不是字符串
                        success: function(arr) {

                            //   var arr=eval(data);

                            var childList;
                            var length = arr.length;
                            for (var i = 0; i < length; i++) {

                                childList = childList +
                                    "<option value=" + arr[i].id + ">" +
                                    arr[i].name + "</option>";
                            }
                            $("#secMenuId").html(childList);

                        },
                        error: function() {
                            alert("出错");
                        }

                    })

                }
            }



            /* 响应新增的菜单联动 */
            function FirstMenuChange() {
                var op = $("#addFirstMenu option:selected");
                var addFirstMenu = op.val();

                if (addFirstMenu == 0) {
                    $("#addSecMenu").html("<option value=0>请选择！</option>");

                } else {
                    $.ajax({
                        type: 'POST',
                        url: '${pageContext.request.contextPath}/getSecMenuByFartherId.html',
                        data: {
                            "parentId": addFirstMenu
                        },
                        dataType: 'json', //要求服务器返回 json对象 而不是字符串
                        success: function(arr) {

                            //   var arr=eval(data);

                            var addSecMenu;
                            var length = arr.length;
                            for (var i = 0; i < length; i++) {

                                addSecMenu = addSecMenu +
                                    "<option value=" + arr[i].id + ">" +
                                    arr[i].name + "</option>";
                            }
                            $("#addSecMenu").html(addSecMenu);

                        },
                        error: function() {
                            alert("出错");
                        }

                    })

                }
            }


            //响应 新增 按钮

            function addRightAction() {

                if ($("#action").val() == "" | $("#action").val().length < 1) {
                    layer.msg("请输入路径！");
                    return false;
                }

                $.ajax({
                    type: 'POST',
                    url: '${pageContext.request.contextPath}/addRightActionAction.html',
                    data: {
                        "rightId": $("#addSecMenu").val(),
                        "action": $("#action").val(),
                        "description": $("#description").val()


                    },
                    dataType: 'json', //要求服务器返回 json对象 而不是字符串
                    success: function(data) {
                        if (data.code == 1) {

                            self.location = "getRightActionList.html";
                            layer.msg("添加成功!");
                        } else {

                            layer.msg("添加失败!")
                        }



                    },
                    error: function() {
                        alert("出错");
                    }

                })

            }
        </script>


        </html>